﻿using System;
using System.Collections.Generic;
using System.Text;
using SAServices.DAL;

namespace SAServices.BLL
{
    internal class CategoryBLL
    {
        internal static List<Model.CategoryInfo> GetRootCategories(Model.ConnectionConext connCtx)
        {
            List<Model.CategoryInfo> retCateInfos = new List<Model.CategoryInfo>();

            //parent guid is empty.
            List<Guid> rootCateIds = CategoryDAL.GetCatIdsByParentId(connCtx, Guid.Empty);

            foreach (Guid tempCateId in rootCateIds)
            {
                Model.CategoryInfo tempCateInfo = CategoryDAL.GetCateInfoById(connCtx, tempCateId);
                retCateInfos.Add(tempCateInfo);
            }

            return retCateInfos;
        }

        internal static List<Model.CategoryInfo> GetSubCategories(Model.ConnectionConext connCtx, Model.CategoryInfo parentCategory)
        {
            List<Model.CategoryInfo> retCateInfos = new List<Model.CategoryInfo>();

            List<Guid> subCateIds = CategoryDAL.GetCatIdsByParentId(connCtx, parentCategory.Id);

            foreach (Guid tempCateId in subCateIds)
            {
                Model.CategoryInfo tempCateInfo = CategoryDAL.GetCateInfoById(connCtx, tempCateId);
                retCateInfos.Add(tempCateInfo);
            }

            return retCateInfos;
        }

        internal static bool UpdateCategory(Model.ConnectionConext connCtx, Model.CategoryInfo updateCategoryInfo)
        {
            return CategoryDAL.UpdateCategory(connCtx, updateCategoryInfo);
        }

        internal static bool AddCategory(Model.ConnectionConext connCtx, Model.CategoryInfo newCategoryInfo)
        {
            return CategoryDAL.AddCategory(connCtx, newCategoryInfo);
        }

        internal static bool DeleteCategory(Model.ConnectionConext connCtx, Guid cateId)
        {
            return CategoryDAL.DeleteCategory(connCtx, cateId);
        }

        internal static Model.CategoryInfo GetCategoryInfoByCateId(Model.ConnectionConext connCtx, Guid cateId)
        {
            return CategoryDAL.GetCateInfoById(connCtx, cateId);
        }
    }
}
